﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace WcfService1
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "StudentSrv" in code, svc and config file together.
    public class StudentSrv : IStudentSrv
    {
        public String addCurrentStudent(int student_id, byte[] UDID)
        {
            try
            {
                using (var db = new questEntities())
                {
                    Current_Users cuObj = new Current_Users();
                    cuObj.device_unique_id = UDID;
                    cuObj.login_time = DateTime.Now;
                    cuObj.fk_st_id = student_id;
                    db.Current_Users.AddObject(cuObj);
                    db.SaveChanges();

                }
            }
            catch (Exception ex) 
            {
               return ex.InnerException.ToString();
            }
            return "add successful";
        }



        public string removeCurrentStudent(int student_id)
        {
            try
            {
                using (var db = new questEntities())
                {
                    Current_Users cuObj = db.Current_Users.First(p => p.fk_st_id == student_id);
                            
                    db.Current_Users.DeleteObject(cuObj);
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                return ex.InnerException.ToString();
            }
            return "delete successful";
        }
    

    }
}
